#!/usr/bin/perl -T
# langident.pl
use warnings;
# lack of use strict;

use CGI qw(:standard);
use Locale::Language;
use Lingua::Ident;
print header, start_html;

if (!param('phrase')) {
   print start_form,
   "->", textfield('phrase'), "<-", end_form;
} else {
   my @dataFiles = qw(data.de data.eu data.en data.fr data.it data.mt
                      data.nl data.ko);
   for (@dataFiles) {
     if ( ! -e $_ ) {
       print "Will not work: File $_ does not exist";
       exit;
     }
   }
   print em(param('phrase')), br, 
   "Looks ";
   my $i = new Lingua::Ident( @dataFiles );
   my $lang = $i->identify(param('phrase'));
   my ($langCode) =  $lang =~ /^(\w{2})/;
   print code2language($langCode), " to me!";
}

print end_html;
